/**
 * 分析页数据请求
 *
 * @版权所有 rem.studio
 */
import { queryAnalysisChartData } from '@/services/chartApi';

export default {
  namespace: 'analysis',

  state: {
    visitsData: [],
    paymentQuantityData: [],
    salesData: [],
    visitsTrendData: [],
    searchData: [],
    cvrData: [],
    flowData: [],
    salesTypeData: [],
    salesTypeOnlineData: [],
    salesTypeOfflineData: [],
    salesRankingData: [],
    visitsRankingData: [],
    analysisData: {},
    loading: false
  },

  effects: {
    *fetch(_, { call, put }) {
      const response = yield call(queryAnalysisChartData);
      yield put({
        type: 'save',
        payload: response
      });
    },
    *fetchSalesData({ payload }, { call, put }) {
      const response = yield call(queryAnalysisChartData, payload);
      yield put({
        type: 'save',
        payload: response
      });
    }
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload.data
      };
    },
    clear() {
      return {
        visitsData: [],
        paymentQuantityData: [],
        salesData: [],
        visitsTrendData: [],
        searchData: [],
        cvrData: [],
        flowData: [],
        salesTypeData: [],
        salesTypeOnlineData: [],
        salesTypeOfflineData: [],
        salesRankingData: [],
        visitsRankingData: [],
        analysisData: {}
      };
    }
  }
};
